package com.example.nextstream.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.nextstream.dto.SessionInfo;
import com.example.nextstream.mapper.ClientSessionMapper;
import com.example.nextstream.models.AssetsInfo;
import com.example.nextstream.models.ClientSession;
import com.example.nextstream.service.AssetsInfoService;
import com.example.nextstream.service.ClientSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.web.context.WebApplicationContext;

import java.util.List;

@Service("clientSessionService")
public class ClientSessionServiceImpl extends ServiceImpl<ClientSessionMapper, ClientSession> implements ClientSessionService {

    @Autowired
    private AssetsInfoService assetsInfoService;
    @Override
    public AssetsInfo getSessionByUUID(String UUID){
        ClientSession  sessioninfo =  baseMapper.selectById(UUID);
        return assetsInfoService.getAssets(sessioninfo.getAssetsId());
    }
    @Override
    public String createSession(Integer assetsId,Integer authorId){
        var cs = new ClientSession();
        cs.setAssetsId(assetsId);
        cs.setAuthorId(authorId);
        baseMapper.insert(cs);
        return cs.getSessionId();
    }

    @Override
    public List<SessionInfo> listSession(int authorId) {
        return baseMapper.getSessionInfo(authorId);
    }

    @Override
    public Boolean deleteSession(String sessionId) {
        baseMapper.deleteById(sessionId);
        return true;
    }
}
